/*******************************************************************/
/* @ All Rights Reserved Copyright (C) 2014 broada,Co.,Ltd.        */
/*                                                                 */
/*  NAME      = t__ems_analyze_direct.c                            */
/*  NOTE      =                                                    */
/*  DATE      = 2017/02/24 by songbb                               */
/*******************************************************************/

#include <CUnit/Basic.h>

#include "frcomm.h"

#include <tibcoems/config.h>
#include <tibcoems/ems_comm.h>
#include <frct_comm.h>
#include <apmtest_comm.h>

extern int __ems_analyze_direct(char *p_payload
                                , unsigned int ui_payload_len);

static int __suite_init(void)
{
    return 0;
}

static int __suite_cleanup(void)
{
    return 0;
}

static void __case1(void)
{
    char *p_bin = (char *) "000000089955ee";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__ems_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_UNKNOWN);
}

static void __case2(void)
{
    char *p_bin = (char *) "000000089955eeab";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__ems_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_UNKNOWN);
}

static void __case3(void)
{
    char *p_bin = (char *) "000000089955eeaa";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__ems_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_SRV2CLIENT);
}

static void __case4(void)
{
    char *p_bin = (char *) "000000309955eeaa1000000797170000001e037478000100067374797065000200036163000500000002037861000100";
    char arr_payload[65536] = {'\0'};

    CU_ASSERT_EQUAL(apmtest_hex_string_to_bin(p_bin, arr_payload, sizeof(arr_payload)), FR_SUCC);

    CU_ASSERT_EQUAL(__ems_analyze_direct(arr_payload, strlen(p_bin) / 2), FR_DIRECT_CLIENT2SRV);
}

int add_suite__ems_analyze_direct(void)
{
    CU_pSuite pSuite = NULL;

    if ((pSuite = CU_add_suite(MODULE_NAME" __ems_analyze_direct()", __suite_init, __suite_cleanup)) == NULL)
        return FR_FAIL;

    if (CU_add_test(pSuite, "case1", __case1) == NULL ||
        CU_add_test(pSuite, "case2", __case2) == NULL ||
        CU_add_test(pSuite, "case3", __case3) == NULL ||
        CU_add_test(pSuite, "case4", __case4) == NULL)
        return FR_FAIL;

    return FR_SUCC;
}
